import React from 'react';
import PropTypes from 'prop-types';
import {Card, Button, Row, Col, Table, Spin} from 'antd';
import {TABLE, DATE_FORMAT, DATETIME_FORMAT} from '../constants';
import {conventEnumValueToString, formatDateTime, formatPercent} from '../utils';
import {salePlanOrderStatus, salePlanAssembleMethod, salePlanOrderResultJudgeResult, currency} from '../Enum';
import {hasPermissions, addMonths} from './utils';
import {PERMISSION} from './constants';
import DescriptionList from 'ant-design-pro/lib/DescriptionList';
import WrappedPopconfirm from '../common/WrappedPopconfirm';
import {submitData, abandonData} from './api';
import styles from './style.css';
import routes from './routes';
const {Description} = DescriptionList;

export class DetailPanel extends React.PureComponent {
    state = {
        loading: false,
    };
    componentDidMount() {
        this.props.init();
    }
    handleUpdateClick = () => {
        this.props.history.push(routes.update.format(this.props.id));
    }
    handleApproveClick = () => {
        this.props.history.push(routes.approve.format(this.props.id));
    }
    
    submitConfirm = () => {
        this.setState({
            loading: true
        });
        const id = this.props.detail.id;
        const rowVersion = this.props.detail.rowVersion;
        const data = {
            id,
            rowVersion,
        };
        submitData([data]).then(res => {
            this.setState({
                loading: false
            });
            if(res.ok)
                this.props.successReturn();
        });
    }
    abandonConfirm = () => {
        this.setState({
            loading: true
        });
        const id = this.props.detail.id;
        const rowVersion = this.props.detail.rowVersion;
        const data = {
            id,
            rowVersion,
        };
        abandonData([data]).then(res => {
            this.setState({
                loading: false
            });
            if(res.ok)
                this.props.successReturn();
        });
    }
    render() {
        const detailData = this.props.detail || {};
        const {options, details, approveDetails} = detailData;
        const {formatMessage} = this.props.intl;
        const operations = [];
        if(hasPermissions(this.props.permissions, PERMISSION.update) && hasPermissions(options, PERMISSION.update))
            operations.push(<Button key="update" onClick={this.handleUpdateClick} size="small">{
                formatMessage({
                    id: 'detailPanel.btn.edit',
                    defaultMessage: '编辑'
                })
            }</Button>);
        if(hasPermissions(this.props.permissions, PERMISSION.submit) && hasPermissions(options, PERMISSION.submit))
            operations.push(
                <WrappedPopconfirm
                    id="submit"
                    key="submit"
                    title={formatMessage({
                        id: 'detailPanel.popconfirm.message',
                        defaultMessage: '是否继续?'
                    })}
                    onConfirm={this.submitConfirm}>
                    <Button key="submit" size="small">{
                        formatMessage({
                            id: 'detailPanel.btn.submit',
                            defaultMessage: '提交'
                        })
                    }</Button>
                </WrappedPopconfirm>);
        if(hasPermissions(this.props.permissions, PERMISSION.approve) && hasPermissions(options, PERMISSION.approve))
            operations.push(<Button key="approve" onClick={this.handleApproveClick} size="small">{
                formatMessage({
                    id: 'detailPanel.btn.approve',
                    defaultMessage: '审核'
                })
            }</Button>);
        if(hasPermissions(this.props.permissions, PERMISSION.abandon) && hasPermissions(options, PERMISSION.abandon))
            operations.push(
                <WrappedPopconfirm
                    id="abandon"
                    key="abandon"
                    title={formatMessage({
                        id: 'detailPanel.popconfirm.message',
                        defaultMessage: '是否继续?'
                    })}
                    onConfirm={this.abandonConfirm}>
                    <Button key="abandon" size="small">{
                        formatMessage({
                            id: 'detailPanel.btn.abandon',
                            defaultMessage: '作废'
                        })
                    }</Button>
                </WrappedPopconfirm>);
        
        let totalN1Quantity = 0;
        let totalN2Quantity = 0;
        let totalN3Quantity = 0;
        let totalN4Quantity = 0;
        let totalN5Quantity = 0;
        let totalN6Quantity = 0;
        let totalN7Quantity = 0;
        let totalN8Quantity = 0;
        let totalN9Quantity = 0;
        let totalN10Quantity = 0;
        let totalN11Quantity = 0;
        let totalN12Quantity = 0;

        let totalVarietyN1 = 0; totalVarietyN1 = details ? details.filter(v => v.n1Quantity).length : 0;
        let totalVarietyN2 = 0; totalVarietyN2 = details ? details.filter(v => v.n2Quantity).length : 0;
        let totalVarietyN3 = 0; totalVarietyN3 = details ? details.filter(v => v.n3Quantity).length : 0;
        let totalVarietyN4 = 0; totalVarietyN4 = details ? details.filter(v => v.n4Quantity).length : 0;
        let totalVarietyN5 = 0; totalVarietyN5 = details ? details.filter(v => v.n5Quantity).length : 0;
        let totalVarietyN6 = 0; totalVarietyN6 = details ? details.filter(v => v.n6Quantity).length : 0;
        let totalVarietyN7 = 0; totalVarietyN7 = details ? details.filter(v => v.n7Quantity).length : 0;
        let totalVarietyN8 = 0; totalVarietyN8 = details ? details.filter(v => v.n8Quantity).length : 0;
        let totalVarietyN9 = 0; totalVarietyN9 = details ? details.filter(v => v.n9Quantity).length : 0;
        let totalVarietyN10 = 0; totalVarietyN10 = details ? details.filter(v => v.n10Quantity).length : 0;
        let totalVarietyN11 = 0; totalVarietyN11 = details ? details.filter(v => v.n11Quantity).length : 0;
        let totalVarietyN12 = 0; totalVarietyN12 = details ? details.filter(v => v.n12Quantity).length : 0;
        if(details)
            details.forEach(d => {
                totalN1Quantity += (d.n1Quantity || 0);
                totalN2Quantity += (d.n2Quantity || 0);
                totalN3Quantity += (d.n3Quantity || 0);
                totalN4Quantity += (d.n4Quantity || 0);
                totalN5Quantity += (d.n5Quantity || 0);
                totalN6Quantity += (d.n6Quantity || 0);
                totalN7Quantity += (d.n7Quantity || 0);
                totalN8Quantity += (d.n8Quantity || 0);
                totalN9Quantity += (d.n9Quantity || 0);
                totalN10Quantity += (d.n10Quantity || 0);
                totalN11Quantity += (d.n11Quantity || 0);
                totalN12Quantity += (d.n12Quantity || 0);
            });
        const columns = [{
            title: formatMessage({
                id: 'detailPanel.column.assembleMethod',
                defaultMessage: '装配方式'
            }),
            dataIndex: 'assembleMethod',
            render: text => conventEnumValueToString(salePlanAssembleMethod, text)
        }, {
            title: formatMessage({
                id: 'detailPanel.column.materialGroupKDBOMCode',
                defaultMessage: '物料组号或BOM编号'
            }),
            dataIndex: 'materialGroupKDBOMCode',
        }, {
            title: formatMessage({
                id: 'detailPanel.column.referenceMaterialGroupKDBOMCode',
                defaultMessage: '参考物料组号或BOM编号'
            }),
            dataIndex: 'referenceMaterialGroupKDBOMCode',
        }, {
            title: formatMessage({
                id: 'detailPanel.column.modelCode',
                defaultMessage: '车型编号'
            }),
            dataIndex: 'modelCode',
        }, {
            title: formatMessage({
                id: 'detailPanel.column.versionCode',
                defaultMessage: '版型编号'
            }),
            dataIndex: 'versionCode',
        }, {
            title: formatMessage({
                id: 'detailPanel.column.manufacturerName',
                defaultMessage: '生产工厂'
            }),
            dataIndex: 'manufacturerName',
        }, {
            title: formatMessage({
                id: 'detailPanel.column.newModel',
                defaultMessage: '是否新车型'
            }),
            dataIndex: 'newModel',
            render: text => text ? formatMessage({
                id: 'detailPanel.column.y',
                defaultMessage: '是'
            }) : formatMessage({
                id: 'detailPanel.column.n',
                defaultMessage: '否'
            }),
        }, {
            title: formatMessage({
                id: 'detailPanel.column.engineCylinder',
                defaultMessage: '排量'
            }),
            dataIndex: 'engineCylinder',
        }, {
            title: formatMessage({
                id: 'detailPanel.column.engineModelName',
                defaultMessage: '发动机型号'
            }),
            dataIndex: 'engineModelName',
        }, {
            title: formatMessage({
                id: 'detailPanel.column.gearboxModel',
                defaultMessage: '变速箱型号'
            }),
            dataIndex: 'gearboxModel',
        }, {
            title: formatMessage({
                id: 'detailPanel.column.transmission',
                defaultMessage: '手自动'
            }),
            dataIndex: 'transmission',
        }, {
            title: formatMessage({
                id: 'detailPanel.column.driveMode',
                defaultMessage: '驱动方式'
            }),
            dataIndex: 'driveMode',
        }, {
            title: formatMessage({
                id: 'detailPanel.column.version',
                defaultMessage: '版型'
            }),
            dataIndex: 'version',
        }, {
            title: formatMessage({
                id: 'detailPanel.column.unitPrice',
                defaultMessage: '单价'
            }),
            dataIndex: 'unitPrice',
        }, {
            title: formatMessage({
                id: 'detailPanel.column.currency',
                defaultMessage: '币种'
            }),
            dataIndex: 'currency',
            render: text => conventEnumValueToString(currency, text)
        }, {
            title: addMonths(2) + formatMessage({
                id: 'detailPanel.column.n1YearOnYearRate',
                defaultMessage: '月同比'
            }),
            dataIndex: 'n1YearOnYearRate',
            render: text => formatPercent(text, 1)
        }, {
            title: addMonths(2) + formatMessage({
                id: 'detailPanel.column.n1MonthOnMonthRate',
                defaultMessage: '月环比'
            }),
            dataIndex: 'n1MonthOnMonthRate',
            render: text => formatPercent(text, 1)
        }, {
            title: addMonths(2) + formatMessage({
                id: 'detailPanel.column.n1Quantity',
                defaultMessage: '月计划数量'
            }),
            dataIndex: 'n1Quantity',
        }, {
            title: addMonths(3) + formatMessage({
                id: 'detailPanel.column.n2Quantity',
                defaultMessage: '月计划数量'
            }),
            dataIndex: 'n2Quantity',
        }, {
            title: addMonths(4) + formatMessage({
                id: 'detailPanel.column.n3Quantity',
                defaultMessage: '月计划数量'
            }),
            dataIndex: 'n3Quantity',
        }, {
            title: addMonths(5) + formatMessage({
                id: 'detailPanel.column.n4Quantity',
                defaultMessage: '月计划数量'
            }),
            dataIndex: 'n4Quantity',
        }, {
            title: addMonths(6) + formatMessage({
                id: 'detailPanel.column.n5Quantity',
                defaultMessage: '月计划数量'
            }),
            dataIndex: 'n5Quantity',
        }, {
            title: addMonths(7) + formatMessage({
                id: 'detailPanel.column.n6Quantity',
                defaultMessage: '月计划数量'
            }),
            dataIndex: 'n6Quantity',
        }, {
            title: addMonths(8) + formatMessage({
                id: 'detailPanel.column.n7Quantity',
                defaultMessage: '月计划数量'
            }),
            dataIndex: 'n7Quantity',
        }, {
            title: addMonths(9) + formatMessage({
                id: 'detailPanel.column.n8Quantity',
                defaultMessage: '月计划数量'
            }),
            dataIndex: 'n8Quantity',
        }, {
            title: addMonths(10) + formatMessage({
                id: 'detailPanel.column.n9Quantity',
                defaultMessage: '月计划数量'
            }),
            dataIndex: 'n9Quantity',
        }, {
            title: addMonths(11) + formatMessage({
                id: 'detailPanel.column.n10Quantity',
                defaultMessage: '月计划数量'
            }),
            dataIndex: 'n10Quantity',
        }, {
            title: addMonths(12) + formatMessage({
                id: 'detailPanel.column.n11Quantity',
                defaultMessage: '月计划数量'
            }),
            dataIndex: 'n11Quantity',
        }, {
            title: addMonths(13) + formatMessage({
                id: 'detailPanel.column.n12Quantity',
                defaultMessage: '月计划数量'
            }),
            dataIndex: 'n12Quantity',
        }, {
            title: formatMessage({
                id: 'detailPanel.column.total',
                defaultMessage: '汇总数量'
            }),
            dataIndex: 'total',
        }, {
            title: formatMessage({
                id: 'detailPanel.column.detailRemark',
                defaultMessage: '清单备注'
            }),
            dataIndex: 'detailRemark',
        }];
        const approveColumns = [{
            title: formatMessage({
                id: 'detailPanel.column.approveSequence',
                defaultMessage: '审核序号'
            }),
            dataIndex: 'approveSequence',
        }, {
            title: formatMessage({
                id: 'detailPanel.column.approverName',
                defaultMessage: '审核人姓名'
            }),
            dataIndex: 'approverName',
        }, {
            title: formatMessage({
                id: 'detailPanel.column.approveTime',
                defaultMessage: '审核时间'
            }),
            dataIndex: 'approveTime',
            render: text => formatDateTime(text, DATETIME_FORMAT)
        }, {
            title: formatMessage({
                id: 'detailPanel.column.approvedContent',
                defaultMessage: '审核意见'
            }),
            dataIndex: 'approvedContent',
        }, {
            title: formatMessage({
                id: 'detailPanel.column.approveResult',
                defaultMessage: '判定结果'
            }),
            dataIndex: 'approveResult',
            render: text => conventEnumValueToString(salePlanOrderResultJudgeResult, text)
        }, {
            title: formatMessage({
                id: 'detailPanel.column.nextOperation',
                defaultMessage: '下一步操作'
            }),
            dataIndex: 'nextOperation',
        }];
        return (
            <div>
                <Spin className="detail" spinning={this.props.loading || this.state.loading}>
                    <Card>
                        <DescriptionList size="large" title={<Row><Col span={12}>{
                            formatMessage({
                                id: 'detailPanel.card.title',
                                defaultMessage: '滚动计划信息'
                            })
                        }</Col>
                        <Col className={`col-align-right ${styles.detail}`} span={12}>{operations}</Col>
                        </Row>}>
                            <Description term={formatMessage({
                                id: 'detailPanel.data.planCode',
                                defaultMessage: '计划编号',
                            })}>{this.props.detail.planCode}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.data.brandCode',
                                defaultMessage: '品牌编号',
                            })}>{this.props.detail.brandCode}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.data.brandName',
                                defaultMessage: '品牌名称',
                            })}>{this.props.detail.brandName}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.data.dealerCode',
                                defaultMessage: '总代编号',
                            })}>{this.props.detail.dealerCode}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.data.dealerName',
                                defaultMessage: '总代名称',
                            })}>{this.props.detail.dealerName}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.data.country',
                                defaultMessage: '国家',
                            })}>{this.props.detail.country}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.data.marketDepartmentName',
                                defaultMessage: '大区',
                            })}>{this.props.detail.marketDepartmentName}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.data.submitYear',
                                defaultMessage: '提报年份',
                            })}>{this.props.detail.submitYear}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.data.submitMonth',
                                defaultMessage: '提报月份',
                            })}>{this.props.detail.submitMonth}</Description>
                            <Description term={addMonths(2) + formatMessage({
                                id: 'detailPanel.data.total',
                                defaultMessage: '滚动计划品种数',
                            })}>{this.props.detail.total}</Description>
                            <Description term={addMonths(2) + formatMessage({
                                id: 'detailPanel.data.detailTotal',
                                defaultMessage: '滚动计划总数量',
                            })}>{this.props.detail.detailTotal}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.data.status',
                                defaultMessage: '状态'
                            })}>{conventEnumValueToString(salePlanOrderStatus, this.props.detail.status)}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.data.createTime',
                                defaultMessage: '提报日期',
                            })}>{formatDateTime(this.props.detail.createTime, DATE_FORMAT)}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.data.creatorName',
                                defaultMessage: '创建人姓名',
                            })}>{this.props.detail.creatorName}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.data.modifierName',
                                defaultMessage: '编辑人姓名',
                            })}>{this.props.detail.modifierName}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.data.modifyTime',
                                defaultMessage: '编辑时间',
                            })}>{formatDateTime(this.props.detail.modifyTime, DATETIME_FORMAT)}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.data.submitterName',
                                defaultMessage: '提交人姓名',
                            })}>{this.props.detail.submitterName}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.data.submitTime',
                                defaultMessage: '提交时间',
                            })}>{formatDateTime(this.props.detail.submitTime, DATETIME_FORMAT)}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.data.abandonerName',
                                defaultMessage: '作废人姓名',
                            })}>{this.props.detail.abandonerName}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.data.abandonTime',
                                defaultMessage: '作废时间',
                            })}>{formatDateTime(this.props.detail.abandonTime, DATETIME_FORMAT)}</Description>
                            <Description term={formatMessage({
                                id: 'detailPanel.data.remark',
                                defaultMessage: '备注',
                            })}>{this.props.detail.remark}</Description>
                        </DescriptionList>
                    </Card>
                    <Card>
                        <DescriptionList title={formatMessage({
                            id: 'detailPanel.table.details',
                            defaultMessage: '清单'
                        })}>
                            <Table
                                className="white-space-nowrap"
                                columns={columns}
                                rowKey="id"
                                pagination={false}
                                dataSource={details}
                                footer={() => <div>
                                    <Row className={styles.alertMargin}>
                                        <DescriptionList>
                                            <Description term={addMonths(2) + formatMessage({
                                                id: 'detailPanel.operation.totalQuantity',
                                                defaultMessage: '月份数量'
                                            })}>{totalN1Quantity}
                                            </Description>
                                            <Description term={addMonths(3) + formatMessage({
                                                id: 'detailPanel.operation.totalQuantity',
                                                defaultMessage: '月份数量'
                                            })}>{totalN2Quantity}
                                            </Description>
                                            <Description term={addMonths(4) + formatMessage({
                                                id: 'detailPanel.operation.totalQuantity',
                                                defaultMessage: '月份数量'
                                            })}>{totalN3Quantity}
                                            </Description>
                                            <Description term={addMonths(5) + formatMessage({
                                                id: 'detailPanel.operation.totalQuantity',
                                                defaultMessage: '月份数量'
                                            })}>{totalN4Quantity}
                                            </Description>
                                            <Description term={addMonths(6) + formatMessage({
                                                id: 'detailPanel.operation.totalQuantity',
                                                defaultMessage: '月份数量'
                                            })}>{totalN5Quantity}
                                            </Description>
                                            <Description term={addMonths(7) + formatMessage({
                                                id: 'detailPanel.operation.totalQuantity',
                                                defaultMessage: '月份数量'
                                            })}>{totalN6Quantity}
                                            </Description>
                                            <Description term={addMonths(8) + formatMessage({
                                                id: 'detailPanel.operation.totalQuantity',
                                                defaultMessage: '月份数量'
                                            })}>{totalN7Quantity}
                                            </Description>
                                            <Description term={addMonths(9) + formatMessage({
                                                id: 'detailPanel.operation.totalQuantity',
                                                defaultMessage: '月份数量'
                                            })}>{totalN8Quantity}
                                            </Description>
                                            <Description term={addMonths(10) + formatMessage({
                                                id: 'detailPanel.operation.totalQuantity',
                                                defaultMessage: '月份数量'
                                            })}>{totalN9Quantity}
                                            </Description>
                                            <Description term={addMonths(2) + formatMessage({
                                                id: 'detailPanel.operation.totalQuantity',
                                                defaultMessage: '月份数量'
                                            })}>{totalN10Quantity}
                                            </Description>
                                            <Description term={addMonths(11) + formatMessage({
                                                id: 'detailPanel.operation.totalQuantity',
                                                defaultMessage: '月份数量'
                                            })}>{totalN11Quantity}
                                            </Description>
                                            <Description term={addMonths(12) + formatMessage({
                                                id: 'detailPanel.operation.totalQuantity',
                                                defaultMessage: '月份数量'
                                            })}>{totalN12Quantity}
                                            </Description>
                                        </DescriptionList>
                                    </Row>
                                    <Row className={styles.alertMargin}>
                                        <DescriptionList>
                                            <Description term={addMonths(2) + formatMessage({
                                                id: 'detailPanel.operation.totalVariety',
                                                defaultMessage: '月份品种数'
                                            })}>{totalVarietyN1}
                                            </Description>
                                            <Description term={addMonths(3) + formatMessage({
                                                id: 'detailPanel.operation.totalVariety',
                                                defaultMessage: '月份品种数'
                                            })}>{totalVarietyN2}
                                            </Description>
                                            <Description term={addMonths(4) + formatMessage({
                                                id: 'detailPanel.operation.totalVariety',
                                                defaultMessage: '月份品种数'
                                            })}>{totalVarietyN3}
                                            </Description>
                                            <Description term={addMonths(5) + formatMessage({
                                                id: 'detailPanel.operation.totalVariety',
                                                defaultMessage: '月份品种数'
                                            })}>{totalVarietyN4}
                                            </Description>
                                            <Description term={addMonths(6) + formatMessage({
                                                id: 'detailPanel.operation.totalVariety',
                                                defaultMessage: '月份品种数'
                                            })}>{totalVarietyN5}
                                            </Description>
                                            <Description term={addMonths(7) + formatMessage({
                                                id: 'detailPanel.operation.totalVariety',
                                                defaultMessage: '月份品种数'
                                            })}>{totalVarietyN6}
                                            </Description>
                                            <Description term={addMonths(8) + formatMessage({
                                                id: 'detailPanel.operation.totalVariety',
                                                defaultMessage: '月份品种数'
                                            })}>{totalVarietyN7}
                                            </Description>
                                            <Description term={addMonths(9) + formatMessage({
                                                id: 'detailPanel.operation.totalVariety',
                                                defaultMessage: '月份品种数'
                                            })}>{totalVarietyN8}
                                            </Description>
                                            <Description term={addMonths(10) + formatMessage({
                                                id: 'detailPanel.operation.totalVariety',
                                                defaultMessage: '月份品种数'
                                            })}>{totalVarietyN9}
                                            </Description>
                                            <Description term={addMonths(11) + formatMessage({
                                                id: 'detailPanel.operation.totalVariety',
                                                defaultMessage: '月份品种数'
                                            })}>{totalVarietyN10}
                                            </Description>
                                            <Description term={addMonths(12) + formatMessage({
                                                id: 'detailPanel.operation.totalVariety',
                                                defaultMessage: '月份品种数'
                                            })}>{totalVarietyN11}
                                            </Description>
                                            <Description term={addMonths(13) + formatMessage({
                                                id: 'detailPanel.operation.totalVariety',
                                                defaultMessage: '月份品种数'
                                            })}>{totalVarietyN12}
                                            </Description>
                                        </DescriptionList>
                                    </Row>
                                </div>}
                                {...TABLE} />
                        </DescriptionList>
                    </Card>
                    <Card>
                        <DescriptionList title={formatMessage({
                            id: 'detailPanel.table.approveDetails',
                            defaultMessage: '审核清单'
                        })}>
                            <Table
                                className="white-space-nowrap"
                                columns={approveColumns}
                                rowKey="id"
                                pagination={false}
                                dataSource={approveDetails}
                                {...TABLE} />
                        </DescriptionList>
                    </Card>
                </Spin>
                <div className="page-toolbar">
                    <Button
                        type="primary"
                        disabled={this.state.loading}
                        onClick={this.props.onCancel}>{formatMessage({
                            id: 'detailPanel.btn.return',
                            defaultMessage: '返回'
                        })}</Button>
                </div>
            </div>
        );
    }
}

DetailPanel.propTypes = {
    detail: PropTypes.object.isRequired,
    id: PropTypes.string.isRequired,
    init: PropTypes.func.isRequired,
    loading: PropTypes.bool.isRequired,
    permissions: PropTypes.array.isRequired,
    onCancel: PropTypes.func.isRequired,
    history: PropTypes.object,
    intl: PropTypes.object,
    successReturn: PropTypes.func,
};

import {connect} from 'react-redux';
import {getDetail, tableSearch} from './actions';
import {injectIntl} from './intl';
import selectorFactory from 'Shared/utils/immutableToJsSelectorFactory';
const getPermissions = selectorFactory(['page', 'domainData', 'permission', 'data']);
const getDetailData = selectorFactory(['page', 'domainData', 'detail', 'data']);
const mapStateToProps = (state, props) => ({
    id: props.id,
    loading: state.getIn(['page', 'domainData', 'detail', 'isFetching']),
    permissions: getPermissions(state),
    detail: getDetailData(state),
});
const mapDispatchToProps = (dispatch, props) => ({
    init: () => dispatch(getDetail(props.id)),
    onCancel: () => {
        props.history.push(routes.query.url());
    },
    successReturn: () => {
        dispatch(tableSearch());
        props.history.push(routes.query.url());
    },
});
export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(DetailPanel));
